import { LOGIN, ROUTES, Token } from '@/services/api'
import { request, METHOD, removeAuthorization } from '@/utils/request'
const BASE_URL = process.env.NODE_ENV === 'production' ? 'http://124.71.234.61:21021' : 'http://124.71.234.61:21021'
/**
 * 登录服务
 * @param name 账户名
 * @param password 账户密码
 * @returns {Promise<AxiosResponse<T>>}
 */
// 登录
export async function login(name, password) {
  return request(`${BASE_URL}/api/services/app/Edu_Distributor/Login?mobile=${name}&password=${password}`, METHOD.OPQ,
    // mobile: name,
    // password: password
  )
}
// 获取token
export async function getToken(name, password) {
  return request(Token, METHOD.POST, {
    userNameOrEmailAddress: name,
    password: password
  })
}

export async function getRoutesConfig() {
  return request(ROUTES, METHOD.GET)
}

/**
 * 退出登录
 */
export function logout() {
  localStorage.removeItem(process.env.VUE_APP_ROUTES_KEY)
  localStorage.removeItem(process.env.VUE_APP_PERMISSIONS_KEY)
  localStorage.removeItem(process.env.VUE_APP_ROLES_KEY)
  // localStorage.removeItem("Authorization")
  removeAuthorization()
}
export default {
  login,
  logout,
  getRoutesConfig
}
